<?php
/**
 * blank sidebox - allows a blank sidebox to be added to your site
 *
 * @package templateSystem
 * @copyright 2007 Kuroi Web Design
 * @copyright Portions Copyright 2003-2007 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_static_news_sidebox.php 2 2008-10-18 02:36:34Z numinix $
 */
  $cache_file = DIR_FS_SQL_CACHE . '/static_rss_sidebox.cache';
  @define(NUMINIX_RSS_PARSER, 'magpierss');
  //$cache = true;
  $content = '';
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">';
  $content .= '<strong>' . TEXT_STATIC_RSS_SIDEBOX . '</strong>';
  // check if a cache file exists and if not, create the content for one
  if ( (!file_exists($cache_file)) || (file_exists($cache_file) && ((time() - filemtime($cache_file)) >= STATIC_RSS_SIDEBOX_CACHE)) ) { // create new cache file
    //$cache = false;
    switch(NUMINIX_RSS_PARSER) {
    case 'magpierss':
      require_once(DIR_WS_CLASSES . 'rss/magpierss/rss_fetch.inc');
      $rss = fetch_rss(STATIC_RSS_SIDEBOX_RSS_FEED);
      $items_array = array();
      $items_array = array_slice($rss->items, 0, (int)STATIC_RSS_SIDEBOX_MAX);
      foreach($items_array as $item) {
        if (zen_not_null(STATIC_RSS_SIDEBOX_DELIMITER)) {
          $content_for_cache .= '<div class="staticRSSArticle">' . STATIC_RSS_SIDEBOX_DELIMITER . ' <a href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item['link'])) . '">' . $item['title'] . '</a></div>';
        } else {
          $content_for_cache .= '<div class="staticRSSArticle"><a href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item['link'])) . '">' . $item['title'] . '</a></div>';
        }
      }
      break;
    case 'patrss':
      require(DIR_WS_CLASSES . "rss/patRSS.php");
      $patRss = new patRSS(STATIC_RSS_SIDEBOX_RSS_FEED);
      $items_array = array();
      $items_array = $patRss->getItems(4);
      foreach($items_array as $item) {
        if (zen_not_null(STATIC_RSS_SIDEBOX_DELIMITER)) {
          $content_for_cache .= '<div class="staticRSSArticle">' . STATIC_RSS_SIDEBOX_DELIMITER . ' <a href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item['link'])) . '">' . $item['title'] . '</a></div>';
        } else {
          $content_for_cache .= '<div class="staticRSSArticle"><a href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item['link'])) . '">' . $item['title'] . '</a></div>';
        }
      }
      break;
    case 'simplepie':
      require_once(DIR_WS_CLASSES . 'rss/simplepie/simplepie.inc');
      $rss = new SimplePie(STATIC_RSS_SIDEBOX_RSS_FEED);
      $rss->handle_content_type();
      foreach ($rss->get_items() as $item) {
        if (zen_not_null(STATIC_RSS_SIDEBOX_DELIMITER)) {
          $content_for_cache .= '<div class="staticRSSArticle">' . STATIC_RSS_SIDEBOX_DELIMITER . ' <a href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item->get_permalink())) . '">' . $item->get_title() . '</a></div>';
        } else {
          $content_for_cache .= '<div class="staticRSSArticle"><a href="' . str_replace('&', '&amp;', str_replace('&amp;', '&', $item->get_permalink())) . '">' . $item->get_title() . '</a></div>';
        }
      }
      break;
    }
    $content_for_cache = '<div class="staticRSSArticles">';
    foreach($items_array as $item) {
      if (zen_not_null(STATIC_RSS_SIDEBOX_DELIMITER)) {
        $content_for_cache .= '<div class="staticRSSArticle">' . STATIC_RSS_SIDEBOX_DELIMITER . ' <a href="' . $item['link'] . '">' . $item['title'] . '</a></div>';
      } else {
        $content_for_cache .= '<div class="staticRSSArticle"><a href="' . $item['link'] . '">' . $item['title'] . '</a></div>';
      }
    }
    $content_for_cache .= '</div>';
    $content .= setCache($cache_file, $content_for_cache);
  } else {
    // get file contents
    $content .= getCache($cache_file);
  }
  $content .= '</div>';
